package com.freewater.javabase.demo.mutithread.interrupt;

/**
 * 线程中端
 */
public class Interrupt {

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();

        Thread.sleep(20);
        myThread.interrupt();
        myThread.join();
    }

    public static class MyThread extends Thread {
        @Override
        public void run() {
            int n = 0;
            while (!interrupted()) {
                System.out.println(n++ + " hello");
            }
            System.out.println("MyThread is interrupted");
        }
    }
}
